<%@ page language="java" contentType="text/html; charset=UTF-8"
	isErrorPage="true" pageEncoding="UTF-8"%>
<style>
.layui-form-item .layui-input-company {
	width: auto;
	padding-right: 10px;
	line-height: 38px;
}
</style>
<div class="layuimini-container layuimini-page-anim">
	<div class="layuimini-main">

		<div class="layui-form layuimini-form" lay-filter="useredit">
			<input type="hidden" name="id" value="">
			<div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="">
                <input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
              <label class="layui-form-label">用户类型</label>
              <div class="layui-input-block">
                  <select name="type" lay-filter="role">
                      <option value="">请选择用户类型</option>
                      <option value="管理员">管理员</option>
                  </select>
              </div>
         </div>
         
         <div class="layui-form-item layui-form-text">
           <label class="layui-form-label">备注</label>
           <div class="layui-input-block">
               <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
           </div>
        </div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" lay-submit
						lay-filter="saveBtn">确认保存</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="/PC_educationms/js/jquery-3.3.1.js"></script>
<script>
	layui.use([ 'form', 'layer', 'miniPage' ], function() {
		var form = layui.form, 
		    layer = layui.layer, 
		    miniPage = layui.miniPage;

		/**
		 * 初始化表单，要加上，不然刷新部分组件可能会不加载
		 */
		form.render();
		// var id = ${userid};
		$.ajax({
        	 url:"/PC_educationms/user/getUser",
			 // data:{id:id},
        	 type:"POST",
        	 success:function(data){
        		 console.log(data);
        		 data = JSON.parse(data);
        			 form.val("useredit", {
        		        	"id":data.id,
        		        	"username":data.username,
        		        	"password":data.password,
        		        	"type":data.type,
        		        	"remark":data.remark
        		      });
        	 }
         })
		

		//监听提交
		form.on('submit(saveBtn)', function(data) {
			var index = layer.alert("确定修改用户信息！", {
				title : '提交修改信息'
			}, function() {
				 console.log(data);
                 $.ajax({
                	 url:"/PC_educationms/user/updateUser",
                	 data:JSON.stringify(data.field),
                	 type:"POST",
                	 dataType:"json",
                     contentType:"application/json",
                	 success:function(data){
                		 console.log(data);
                   		 data = JSON.parse(data);
                   		 if(data.msg == "ok") {
                   			// 关闭弹出层
                   			layer.close(index);
            				miniPage.hashHome();
                   		 }else{
                             layer.alert('修改失败！请输入正确信息。'+(data.handle!=undefind?data.handle:""));
                       	}
                	 }
                 })
				
			});
			return false;
		});

	});
</script>